<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="aa" uri="/WEB-INF/tld/ajaxanywhere.tld" %>
<%@ taglib prefix="mytag" tagdir="/WEB-INF/tags" %>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>添加</title>
<script src="/webjars/jquery/3.5.1/jquery.js"></script>
<script src="/aa.js"></script>
<link rel="stylesheet" href="/resources/css/bootstrap.min.css" />
<link rel="stylesheet" href="/resources/css/dashboard.css" />
<%@include file="./dialog/dialog.jsp"%>
</head>
<body>
 <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">添加</h5>
</div>
<div class="modal-body">
<zone name="addzone">
 <form id="addForm" name="addForm" action="">
 <input type="hidden"  value='${callBack}' id="callBack">
  <div class="mb-3">
<span>
<input type="text" class="form-control" id="id" name="id" placeholder="请填写id">
</span>
</div>
  <div class="mb-3">
<span>
<input type="text" class="form-control" id="name" name="name" placeholder="请填写姓名">
</span>
</div>
 <div class="mb-3">
<span></span><span id="aazone.zoneProvince">
<!-- @end of zone [zoneProvince]@ --></span>
</div>
<div class="mb-3">
<span></span><span id="aazone.zoneCity">
<!-- @end of zone [zoneCity]@ --></span>
</div>
<div class="mb-3">
<span></span><span id="aazone.zoneCounty">
<!-- @end of zone [zoneCounty]@ --></span>
</div>
</form>
</zone>
 <div class="modal-footer">
        <button type="button" class="btn btn-secondary" onclick="canceldialog();">关闭</button>
        <button type="button" class="btn btn-primary" onclick="confirmDemo();">保存</button>
 </div>
</body>
<script type="text/javascript">
 
 function getOpener (){
	if(opener){
			return opener.window; 
	}else {
			return parent.window;
	}
}


function canceldialog(){
	if(getOpener()){
		getOpener().dialogCancel();
	}
}


let ajaxProvince = ajaxObj();
let ajaxcity = ajaxObj();
let ajaxcounty = ajaxObj();
//用于提交时使用
let ajaxAddRefDemo= ajaxObj();

function ajaxObj(){
	let ajaxObj = new AjaxAnywhere();
	ajaxObj.bindById();
	return ajaxObj;
}

async function asynSubmitAjax(ajaxAny,url,zone){
	return new Promise((resolve,reject)=>{
		ajaxAny.formName="addForm";
		document.getElementById("addForm").action = url;
		ajaxAny.getZonesToReload = function(){
			return zone;
		}
		ajaxAny.submitAJAX();
		
		ajaxAny.onAfterResponseProcessing=function(){
			resolve();
		}
		
	});
}

//刷新市区域
function proviceChange(){
	asynSubmitAjax(ajaxcity,'/refresh/t/listcity', 'zoneCity');
}

//刷新县区域
function cityChange(){
	asynSubmitAjax(ajaxcounty,'/refresh/f/listcounty', 'zoneCounty');
}

//刷新列表区域
function countyChange(){
}

function confirmDemo(){
	asynSubmitAjax(ajaxAddRefDemo, "/refresh/j/addRefDemo", 'addzone').then((resolve,reject)=>{
		alert("更新成功!");
		var callBack = $("#callBack").val();
		eval("getOpener()."+callBack+"()");	
	});
}


(async function(){
	//省份刷新
	await asynSubmitAjax(ajaxProvince,'/refresh/j/listprovince', 'zoneProvince');
	//市刷新
	await asynSubmitAjax(ajaxcity,'/refresh/t/listcity', 'zoneCity');
	//县刷新
	await asynSubmitAjax(ajaxcounty,'/refresh/f/listcounty', 'zoneCounty');
})();


</script>
<script src="/resources/js/http.js"></script>
</html>
